package com.weimi.phh.base;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by Administrator on 2015/9/9.
 */
public abstract class BaseFragment extends Fragment {

    protected Activity mActivity;
    protected View rootView; // 该fragment显示view的根view

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
        mActivity  = getActivity();
    }

    protected void init() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if(rootView == null){
            rootView =  initView();
        }else{
            //貌似没有什么意思？？
            //((ViewGroup)rootView.getParent()).removeView(rootView);
            container.removeView(rootView);
        }
        return rootView;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData();
    }

    /**
     * 初始化数据，事件等等
     */
    protected void initData() {
    }

    /**
     * 初始化视图
     * @return
     */
    protected abstract View initView();
}
